/**
 * 
 */
package uk.co.lunagroup.files;

import java.io.File;

import javax.swing.JFileChooser;

/**
 * . Allows user to pick up file
 * 
 * @author Robert Kowalski
 * @version 0.1
 * @return choosen file as File type
 */
public class FileOperations {

	/**
	 * . Method pick up single file
	 * 
	 * @return file as File type
	 */
	public static File pickFile() {
		// first configure what we want JFileChooser should look like.
		// we are using created ParametersForJFileChooser class
		ParametersForJFileChooser configuration = new ParametersForJFileChooser();
		configuration.setDialogTitle("Choose file");

		// now let's build customized JFileChooser with parameters described
		// above
		JFileChooser chooser = CustomizedJFileChooser
				.buildJFileChooser(configuration);
		chooser.showOpenDialog(null);
		File file = chooser.getSelectedFile();
		file.getAbsolutePath();

		return file;
	}

	/**
	 * . method choose folder name
	 * 
	 * @return folder name in File format
	 */
	public static File pickFolder() {
		// first configure what we want JFileChooser should look like.
		// we are using created ConfigureJFileChooser class
		ParametersForJFileChooser configuration = new ParametersForJFileChooser();
		configuration.setDialogTitle("Choose folder");
		configuration.setSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		configuration.setPathName(".");

		// now let's build customized JFileChooser with parameters described
		// above
		JFileChooser chooser = CustomizedJFileChooser
				.buildJFileChooser(configuration);
		chooser.showOpenDialog(null);
		File file = chooser.getSelectedFile();
		file.getAbsolutePath();

		return file;
	}

	/**
	 * . method chooses Excel file (xls, xlsx)
	 * 
	 * @return file name in File format
	 */
	public static File pickExcelFile() {
		// first configure what we want JFileChooser should look like.
		// we are using created ConfigureJFileChooser class
		ParametersForJFileChooser configuration = new ParametersForJFileChooser();
		configuration.setDialogTitle("Choose excel file");
		configuration.setPathName("C:\\Users\\robert.kowalski\\Desktop\\");
		String filterDescription = "Choose excel files - xls, xlsx";
		String[] filterExtensions = { "xls", "xlsx" };
		ExtensionFileFilter inputFilter = new ExtensionFileFilter(
				filterDescription, filterExtensions);
		configuration.setFilter(inputFilter);

		// now let's build customized JFileChooser with parameters described
		// above
		JFileChooser chooser = CustomizedJFileChooser
				.buildJFileChooser(configuration);
		chooser.showOpenDialog(null);
		File file = chooser.getSelectedFile();
		file.getAbsolutePath();

		return file;
	}

	public static File pickXMLFile() {
		// first configure what we want JFileChooser should look like.
		// we are using created ConfigureJFileChooser class
		ParametersForJFileChooser configuration = new ParametersForJFileChooser();
		configuration.setDialogTitle("Choose XML file");
		configuration.setPathName("C:\\Users\\robert.kowalski\\Desktop\\");
		String filterDescription = "Choose XML file - xml";
		String[] filterExtensions = { "xml" };
		ExtensionFileFilter inputFilter = new ExtensionFileFilter(
				filterDescription, filterExtensions);
		configuration.setFilter(inputFilter);

		// now let's build customized JFileChooser with parameters described
		// above
		JFileChooser chooser = CustomizedJFileChooser
				.buildJFileChooser(configuration);
		chooser.showOpenDialog(null);
		File file = chooser.getSelectedFile();
		file.getAbsolutePath();

		return file;
	}
}